home *** CD-ROM | disk | FTP | other *** search
- Path: grimsel.zurich.ibm.com!usenet
- From: Keith Whittingham <wgk@zurich.ibm.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Virtual function does not make any sense unless it is pure.
- Date: Fri, 12 Apr 1996 11:02:43 -0700
- Organization: IBM Zurich Research Laboratory
- Message-ID: <316E9AC3.1124@zurich.ibm.com>
- References: <4kkhbc$nj4@brahms.udel.edu>
- NNTP-Posting-Host: pine.zurich.ibm.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (Win16; I)
-
- Yue-hong Zheng wrote:
- >
- > Can any body give me any examples to show non-pure virtual function does
- > make sense?
-
-
- #include <iostream.h>
-
- class Base
- {
- public:
- virtual const char *Name() { return "Base"; }
- };
-
-
- class Derived:
- public Base
- {
- public: // Ctors, dtors...
- virtual const char *Name() { return "Derived"; }
- };
-
-
- #pragma argsused
- int main(
- int argc,
- char *argv[])
- {
- int DosRetCode = 0;
- Base b, *bp;
- Derived d;
-
- bp = &b;
- cout << bp->Name() << endl;
- bp = &d;
- cout << bp->Name() << endl;
-
-
- return DosRetCode;
- }
-
-
- That help.
-
- The "pure" in pure virtual is used exactly the same way but where
- you want to force the user of a base class to implement a method
-
- --
- Keith Whittingham
- wgk@zurich.ibm.com
-